﻿using MediatR;
using Production_Set.API.Application.Commands.Resourctes;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.Order;
using THE_WIND_RISES.Common.Domans.Produce.Resources;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Set.API.Application.Commands.Orderers
{
    /// <summary>
    /// 审批
    /// </summary>
    public class OrdersStateHandler : IRequestHandler<OrdersStateCommend, Result>
    {
        private readonly IBaseRepository<Orders> Orders;

        public OrdersStateHandler(IBaseRepository<Orders> Orders)
        {
            this.Orders = Orders;
        }

        public async Task<Result> Handle(OrdersStateCommend request, CancellationToken cancellationToken)
        {
            var results = new Result() { Code = (int)CommonErrorCodes.Update };

            //var sql1 = "SELECT ApprovalStatus FROM Resource WHERE ResourceId="+request.ResourceId;
            //var life = Resource.GetAll(sql1).ToList();

            //var ADEnum = life

            string sql = "UPDATE Orders SET ApprovalStatusDD=@ApprovalStatusDD WHERE OrdersId=" + request.OrdersId;
            var list = Orders.Update(sql, new
            {
                ApprovalStatusDD = request.ApprovalStatusDD + 1
            });
            if (list != null)
            {
                results.Code = (int)CommonErrorCodes.Success;
                results.Msg = "修改成功";
            }

            return results;
        }
    }
}
